<template>
  <el-container class="main-container">
    <!-- 头部布局 -->
    <el-header>
      <!-- logo 和项目名称 -->
      <div class="left-box">
        <img src="../assets/logo.png" class="main-logo" />
        <span class="main-title">新冠物资管理系统</span>
      </div>
      <!-- 用户登录和展示的头像 -->
      <div class="right-box">
        <el-dropdown>
          <!-- <img src="../assets/logo.png" alt="" class="main-heard-logo" /> -->
           <span style="color:white" class="el-dropdown-link">{{this.username}}<i class="el-icon-arrow-down el-icon--right"></i></span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-house">系统首页</el-dropdown-item>
            <el-dropdown-item icon="el-icon-ship">交流探讨</el-dropdown-item>
            <el-dropdown-item icon="el-icon-switch-button"
              >退出登录</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '60px' : '200px'" v-infinite-scroll="load" >
        <div @click="toggleCollapse" class="toggle-box">|||</div>
        <el-menu
          :default-active="activePath"
          background-color="#5c5f62"
          text-color="#fff"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
          :unique-opened="true"
        >
          <MenuTree :menuList="MenuList" />
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import MenuTree from "../components/MenuTree.vue";
export default {
  name: "Home",
  data() {
    return {
      isCollapse: false,
      MenuList: [],
      activePath: "",
    };
  },
  created() {
    this.menuTreeList();
  },
  methods: {
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    load () {
        this.count += 2
      },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    async menuTreeList() {
      await this.$http
        .post(`/sys/resource/list`, {}, { headers: { token: this.token } })
        .then((response) => {
          this.MenuList = response.data;
        });
    },
  },
  components: {
    MenuTree,
  },
};
</script>
<style  lang="less" scoped>
.main-container {
  height: 100%;
}
.el-header {
  background-color: #5c5f62;
  color: #ffffff;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  font-size: 20px;
}
.left-box {
  display: flex;
  align-items: center;
}
.right-box {
  display: flex;
  align-items: center;
}
.main-logo {
  width: 60px;
  height: 60px;
  margin: 0px 0px 10px 15px;
}
.main-heard-logo {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: #ffffff;
}
.main-title {
  margin-left: 15px;
}
.el-aside {
  background-color: #5c5f62;
  color: rgb(252, 249, 249);
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
/* 展开收起 */
.toggle-box {
  font-size: 15px;
  font-weight: bold;
  line-height: 25px;
  color: white;
  letter-spacing: 0.2em;
  text-align: center;
  cursor: pointer;
}
.el-menu {
  border: none;
}
</style>